#!/bin/sh
# author:lijian
# date:2014-04-22
# desc:just for fun!


RESIN_BIN_DIR=/usr/local/resin/bin
BAK_DATE=`date +%Y%m%d%H%M%S`

API_ROOT_DIR=/home/resin/data/jsp/api.uc.frogshealth.com
API_JSP_DIR=${API_ROOT_DIR}/WebRoot
API_CURR_DIR=/home/resin/data/war/api.uc.frogshealth.com

ADMIN_ROOT_DIR=/home/resin/data/jsp/admin.uc.frogshealth.com
ADMIN_JSP_DIR=${ADMIN_ROOT_DIR}/WebRoot
ADMIN_CURR_DIR=/home/resin/data/war/admin.uc.frogshealth.com

FRONT_ROOT_DIR=/home/resin/data/jsp/uc.frogshealth.com
FRONT_JSP_DIR=${FRONT_ROOT_DIR}/WebRoot
FRONT_CURR_DIR=/home/resin/data/war/uc.frogshealth.com

#
echo "����${API_ROOT_DIR} �� ${API_CURR_DIR}/WebRoot_${BAK_DATE}.tar.gz"
tar -C ${API_ROOT_DIR} -zcvf ${API_CURR_DIR}/WebRoot_${BAK_DATE}.tar.gz WebRoot --exclude WEB-INF/tmp --exclude WEB-INF/work

echo "������ϣ���ѹ�ļ�ucenter-api.war"
cd ${API_CURR_DIR}
if [ -d ${API_CURR_DIR}/WebRoot ]
then
echo "ɾ������WebRoot�ļ�"
rm -rf WebRoot
fi
unzip ucenter-api.war -d WebRoot
rm -rf ${API_JSP_DIR}/WEB-INF/lib/*
rm -rf ${API_JSP_DIR}/WEB-INF/classes/*

echo "�����ļ�"
cp -rf WebRoot/* ${API_JSP_DIR}
rm -rf WebRoot

if [ ! -d ${API_JSP_DIR}/images ]
then
ln -s ${API_ROOT_DIR}/images ${API_JSP_DIR}
echo "ln ${API_JSP_DIR} images"
fi

if [ ! -d ${API_JSP_DIR}/images2 ]
then
ln -s ${API_ROOT_DIR}/images2 ${API_JSP_DIR}
echo "ln ${API_JSP_DIR} images2"
fi

#
echo "backup ${ADMIN_ROOT_DIR} to ${ADMIN_CURR_DIR}/WebRoot_${BAK_DATE}.tar.gz"
tar -C ${ADMIN_ROOT_DIR} -zcvf ${ADMIN_CURR_DIR}/WebRoot_${BAK_DATE}.tar.gz WebRoot --exclude WEB-INF/tmp --exclude WEB-INF/work

echo "backup success ! unzip......ucenter-admin.war"
cd ${ADMIN_CURR_DIR}
if [ -d ${ADMIN_CURR_DIR}/WebRoot ]
then
echo "delete old WebRoot"
rm -rf WebRoot
fi
unzip ucenter-admin.war -d WebRoot
rm -rf ${ADMIN_JSP_DIR}/WEB-INF/lib/*
rm -rf ${ADMIN_JSP_DIR}/WEB-INF/classes/*

echo "update....."
cp -rf WebRoot/* ${ADMIN_JSP_DIR}
rm -rf WebRoot

#
echo "����${FRONT_ROOT_DIR} �� ${FRONT_CURR_DIR}/WebRoot_${BAK_DATE}.tar.gz"
tar -C ${FRONT_ROOT_DIR} -zcvf ${FRONT_CURR_DIR}/WebRoot_${BAK_DATE}.tar.gz WebRoot --exclude WEB-INF/tmp --exclude WEB-INF/work

echo "������ϣ���ѹ�ļ�ucenter-front.war"
cd ${FRONT_CURR_DIR}
if [ -d ${FRONT_CURR_DIR}/WebRoot ]
then
echo "ɾ������WebRoot�ļ�"
rm -rf WebRoot
fi
unzip ucenter-front.war -d WebRoot
rm -rf ${FRONT_JSP_DIR}/WEB-INF/lib/*
rm -rf ${FRONT_JSP_DIR}/WEB-INF/classes/*

echo "�����ļ�"
cp -rf WebRoot/* ${FRONT_JSP_DIR}
rm -rf WebRoot

PATH=/usr/java/jdk1.7.0_51/bin:/usr/local/subversion/bin/:$PATH:$HOME/bin
export PATH
JAVA_HOME=/usr/java/jdk1.7.0_51
export JAVA_HOME
CLASSPATH=/usr/java/jdk1.7.0_51/lib:/usr/java/jdk1.7.0_51/jre/lib
export CLASSPATH

echo $JAVA_HOME
echo "stop resin "
${RESIN_BIN_DIR}/httpd.sh stop -server front_ucenter
${RESIN_BIN_DIR}/httpd.sh stop -server amin_ucenter
${RESIN_BIN_DIR}/httpd.sh stop -server api_ucenter
sleep 3s
echo "start resin"
${RESIN_BIN_DIR}/httpd.sh start -server front_ucenter
${RESIN_BIN_DIR}/httpd.sh start -server amin_ucenter
${RESIN_BIN_DIR}/httpd.sh start -server api_ucenter
exit 0
